package com.newtouch.bxzs.database.synchronize.batch.step;

import com.newtouch.bxzs.database.synchronize.batch.process.ProcesorCustomer;
import com.newtouch.bxzs.database.synchronize.batch.reader.ReaderData;
import com.newtouch.bxzs.database.synchronize.batch.steplistener.CustomerStepListener;
import com.newtouch.bxzs.database.synchronize.batch.writer.WriterCustomer;
import com.newtouch.bxzs.database.synchronize.model.CustomerBO;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 客户同步step
 *
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2021/1/7 10:52</td>
 * <td>Amour</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author yuanjie
 * @version 1.0.0
 * @since 1.0.0
 */
@Component
public class CustomerStep {

    @Autowired
    private StepBuilderFactory stepBuilderFactory;

    @Autowired
    private ReaderData readerData;

    @Autowired
    private WriterCustomer writerCustomer;

    @Autowired
    private ProcesorCustomer procesorCustomer;

    @Autowired
    private CustomerStepListener stepListener;


    /**批处理同步客户数据*/
    public Step synchronizeCustomerStep(){
        return stepBuilderFactory.get("synchronizeCustomerStep")
                .listener(stepListener)
                .<CustomerBO, CustomerBO>chunk(100)
                .reader(readerData.synchronizedCustomerList())
                .processor(procesorCustomer.processorCustomer())
                .writer(writerCustomer.addCustomerList())
                .faultTolerant()
                .skip(Exception.class)
                .skipLimit(10)
                .build();
    }
}
